package com.xzq.springframework.beans;

import cn.hutool.core.util.StrUtil;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author xzq
 * @Description //TODO
 * @Date 2021/11/24 11:04
 * @Version 1.0.0
 **/
@Data
public class PropertyValues {

    private List<PropertyValue> propertyValueList = new ArrayList<>();

    public void addPropertyValue(PropertyValue propertyValue) {
        propertyValueList.add(propertyValue);
    }

    public PropertyValue[] getPropertyValues() {
        return propertyValueList.toArray(new PropertyValue[0]);
    }
    public List<PropertyValue> getPropertyValueList() {
        return propertyValueList;
    }

    /**
     * 根据名称获取PropertyValue
     */
    public PropertyValue getPropertyValue(String name) {
        if (StrUtil.isEmpty(name)) {
            return null;
        }
        for (PropertyValue propertyValue : propertyValueList) {
            if (propertyValue.getName().equals(name)) {
                return propertyValue;
            }
        }
        return null;
    }
}
